import axios from "axios";

const reservoirBaseUrl= "http://localhost:8082";
const reservoirRequest={
    loadReservoirs(reservoir,callBack){
        let url = reservoirBaseUrl + "/reservoir/list?";
        if(reservoir){
            if(reservoir.reservoirName){
                url += "&reservoirName=" + reservoir.reservoirName;
            }
            if(reservoir.reservoirHouseId){
                url += "&reservoirHouseId=" + reservoir.reservoirHouseId;
            }
        }
        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    insert(reservoir,callBack){
        let url = reservoirBaseUrl + "/reservoir/insert";
        axios.post(url,reservoir)
            .then(res=>{
                callBack(res.data);
            })
    },
    update(reservoir,callBack){
        let url  = reservoirBaseUrl + "/reservoir/update";
        axios.put(url,reservoir)
            .then(res=>{
                callBack(res.data);
            })
    },
    selectById(reservoirId,callBack){
        let url = reservoirBaseUrl + "/reservoir/selectById?reservoirId=" + reservoirId;
        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    delete(reservoirId,callBack){
        let url = reservoirBaseUrl + "/reservoir/delete?reservoirId=" + reservoirId;
        axios.delete(url)
            .then(res=>{
                callBack(res.data);
            })
    }
}

export default reservoirRequest;
